<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<title>Aplicação do Algoritmo Filtering para Dados Agrícolas</title>

	<link rel="stylesheet" type="text/css" media="screen" href="theme/default/style.css"  />
	<link rel="stylesheet" type="text/css" media="screen" href="theme/default/google.css" />
	<link rel="stylesheet" type="text/css" media="screen" href="theme/default/style.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="theme/css/map.css" />

	<!--<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true_or_false&amp;key=ABQIAAAA9g31osZ3qPY5sFA_1nsoThSls9MZZQqkG4Wfe-D35zFtWgE5IhTpvN4NrBcU3g-CCJELHF1ks4L1fA" type="text/javascript"></script>-->
	<!--<script src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers"></script>-->
	<script type="text/javascript" src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
    <script type="text/javascript" src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=8Y.XtG_V34HDsb83udB57UFrzHNGg1HvtpFFiRpTdHFx6d5nZLGRuRQ9i9rRkWqQ_nY-'></script>
    <script type="text/javascript" src="theme/js/OpenLayers.js"></script>
	<script type="text/javascript">
		OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
		var map;
		OpenLayers.IMAGE_RELOAD_ATTEMPTS = 5;
		OpenLayers.DOTS_PER_INCH = 25.4 / 0.28;
		var options = {
                projection: new OpenLayers.Projection("EPSG:900913"),
                displayProjection: new OpenLayers.Projection("EPSG:4326"),
                // map horizontal units are meters
                units: "m",
                // this resolution displays the globe in one 256x256 pixel tile
                maxResolution: 156543.0339,
                // these are the bounds of the globe in sperical mercator
                maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
                                                 20037508, 20037508),
                controls: [new OpenLayers.Control.Navigation(),
                           new OpenLayers.Control.PanZoomBar()]
			};

		function init() {
			map = new OpenLayers.Map('map',options);
			map.addControl(new OpenLayers.Control.LayerSwitcher());

            // cria as Layers do Google Maps
			var gphy = new OpenLayers.Layer.Google(
				"Google Physical",
				{type: G_PHYSICAL_MAP,'sphericalMercator': true}
			);
			var gmap = new OpenLayers.Layer.Google(
				"Google Street", // the default
				{'sphericalMercator': true}
			);
			var ghyb = new OpenLayers.Layer.Google(
				"Google Hybrid",
				{type: G_HYBRID_MAP,'sphericalMercator': true}
			);
			var gsat = new OpenLayers.Layer.Google(
				"Google Satellite",
				{type: G_SATELLITE_MAP,'sphericalMercator': true}
			);

            // cria as Layers do Yahoo! Maps
            var yahoo = new OpenLayers.Layer.Yahoo(
                "Yahoo Street",
                {'sphericalMercator': true, transitionEffect: 'resize'}
            );
            var yahoosat = new OpenLayers.Layer.Yahoo(
                "Yahoo Satellite",
                {'type': YAHOO_MAP_SAT, 'sphericalMercator': true, transitionEffect: 'resize'}
            );
            var yahoohyb = new OpenLayers.Layer.Yahoo(
                "Yahoo Hybrid",
                {'type': YAHOO_MAP_HYB, 'sphericalMercator': true, transitionEffect: 'resize'}
            );

            var furcata_original_nao = new OpenLayers.Layer.WMS(
                "Furcata Original Não",
                "http://127.0.0.1:8081/cgi-bin/mapserv.exe?map=c:\\maps\\wms_furcata_original_nao.map",
                {
                    layers: "furcata_original_nao",
                    styles: '',
                    srs: 'EPSG:4269',
                    format: 'image/png',
                    tiled: 'true',
                    transparent: true
                },
                {
                    'opacity': 0.75,
                    'isBaseLayer': false,
                    'wrapDateLine': true
                }
            );

            var furcata_original_sim = new OpenLayers.Layer.WMS(
                "Furcata Original Sim",
                "http://127.0.0.1:8081/cgi-bin/mapserv.exe?map=c:\\maps\\wms_furcata_original_sim.map",
                {
                    layers: "furcata_original_sim",
                    styles: '',
                    srs: 'EPSG:4269',
                    format: 'image/png',
                    tiled: 'true',
                    transparent: true
                },
                {
                    'opacity': 0.75,
                    'isBaseLayer': false,
                    'wrapDateLine': true
                }
            );

            var furcata_garp = new OpenLayers.Layer.WMS(
                "Furcata GARP",
                "http://127.0.0.1:8081/cgi-bin/mapserv.exe?map=c:\\maps\\wms_furcata_garp.map",
                {
                    layers: "furcata_garp",
                    styles: '',
                    srs: 'EPSG:4269',
                    format: 'image/png',
                    tiled: 'true',
                    transparent: true
                },
                {
                    'opacity': 0.75,
                    'isBaseLayer': false,
                    'wrapDateLine': true
                }
            );

            var jacto = new OpenLayers.Layer.WMS(
				"Produtividade de Milho",
				"http://127.0.0.1:8081/cgi-bin/mapserv.exe?map=c:\\maps\\wms_jacto.map",
				{
                    layers: "jacto",
                    styles: '',
                    srs: 'EPSG:4269',
                    format: 'image/png',
                    tiled: 'true',
                    transparent: true
				},
				{
                    'opacity': 0.75,
                    'isBaseLayer': false,
                    'wrapDateLine': true
				}
            );

            var bee = new OpenLayers.Layer.WMS(
				"Australopitecus",
				"http://127.0.0.1:8081/cgi-bin/mapserv.exe?map=c:\\maps\\wms_bee.map",
				{
                    layers: "geospatialelements",
                    styles: '',
                    srs: 'EPSG:4326',
                    format: 'image/png',
                    tiled: 'true',
                    transparent: true
				},
				{
                    'opacity': 0.75,
                    'isBaseLayer': false,
                    'wrapDateLine': true
				}
            );

		   /*var wms = new OpenLayers.Layer.WMS( "VMap0",
				   "http://127.0.0.1:8081/tilecache/tilecache.py",
				   {layers: "geospatialelements",
					styles: '',
					srs: 'EPSG:4326',
					format: 'image/png',
					tiled: 'true',
					/* tilesOrigin : "143.60260815000004,-43.851764249999995",*/
				  /*  transparent: true
				   },
				   {
					'opacity': 0.75, 'isBaseLayer':false, 'wrapDateLine': true
				   });*/

		  /*var wms = new OpenLayers.Layer.WMS( "VMap0",
					"http://127.0.0.1:8081/tilecache/tilecache.py",
					{layers: 'geospatialelements',
					 format: 'image/png',
					 transparent: true,'isBaseLayer': false });*/

            var vectors = new OpenLayers.Layer.Vector("Marcadores", {isBaseLayer: false});

            map.addLayers([gphy,
                           gmap,
                           ghyb,
                           gsat,
                           yahoo,
                           yahoohyb,
                           yahoosat,
                           furcata_original_nao,
                           furcata_original_sim,
                           furcata_garp,
                           //jacto,
                           //bee,
                           vectors]);

			var info = new OpenLayers.Control.WMSGetFeatureInfo({
			url: "http://127.0.0.1:8081/cgi-bin/mapserv.exe?map=c:\\maps\\wms_postgis.map",
			title: 'Identify features by clicking',
			queryVisible: true,
			vendorParams: {
			"FEATURE_COUNT": "1000"},
			eventListeners: {
				getfeatureinfo:
					function(event) {
					 if((event.text).length != 1) {
					  map.addPopup(new OpenLayers.Popup.FramedCloud(
						  "chicken",
						  map.getLonLatFromPixel(event.xy),
						  null,
						  event.text,
						  null,
						  true
					  ));
					 }
					}
			}
		});
		map.addControl(info);
		info.activate();

		var report = function(e) {
				OpenLayers.Console.log(e.type, e.feature.id);
			};

		var highlightCtrl = new OpenLayers.Control.SelectFeature(vectors, {
				hover: true,
				highlightOnly: true,
				renderIntent: "temporary",
				eventListeners: {
					beforefeaturehighlighted: report,
					featurehighlighted: report,
					featureunhighlighted: report
				}
			});

		 var selectCtrl = new OpenLayers.Control.SelectFeature(vectors,
				{clickout: true}
			);

		 map.events.register("click", map,
		 function(e) {
		  // Read the map coordinates from the click event
		  var lonlat = map.getLonLatFromViewPortPx(e.xy).transform(map.projection,map.displayProjection);

		  // Construct the query URL
		  var url = "click-query.php";
		  url += "?lon=" + lonlat.lon;
		  url += "&lat=" + lonlat.lat;

		  // Load the URL into an iframe
		  document.getElementById("query").src = url;
		  });
	    map.addControl(highlightCtrl);
		map.addControl(selectCtrl);
		map.addControl(new OpenLayers.Control.EditingToolbar(vectors));
		//map.addControl(new OpenLayers.Control.Permalink('permalink'));
		map.addControl(new OpenLayers.Control.Scale({div: document.getElementById("scale")}));
		map.addControl(new OpenLayers.Control.MousePosition({div: document.getElementById("location")}));
		map.addControl(new OpenLayers.Control.KeyboardDefaults);
		var panel = new OpenLayers.Control.Panel(
            {div: document.getElementById("panel")}
        );
		map.addControl(panel);
		var history = new OpenLayers.Control.NavigationHistory();
		map.addControl(history);
		panel.addControls(
            [history.next,
             history.previous]
        );

        var longitude = -50.021439;
        var latitude = -22.679066;
        var zoom = 3;
		map.setCenter(new OpenLayers.LonLat(longitude, latitude).transform(map.displayProjection, map.projection), zoom);
		highlightCtrl.activate();
		selectCtrl.activate();
		}
	</script>
</head>

<body onload="init()">
	<div id="map" class="smallmap"></div>
		<table>
			<tr>
				<td width="650px">
					<div id="scale"></div>
				</td>
				<td>
					<div id="location">location</div>
					<?php
					//$output = shell_exec('java -jar filtragem.jar ');
					//echo "<pre>$output</pre>";
					?>
			   </td>
			</tr>
		</table>
	<div id="panel"></div>
	<iframe id="query"></iframe>
	<!-- <div id="nodeList">Click the map to get feature info</div> -->
</body>

</html>
